<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/13
 * Time: 14:18
 */

namespace mikkle\tp_swoole;


class SwooleRequestTools
{
    static public function getRequestPathInfo(\swoole_http_request $request)
    {
        return ltrim($request->server["path_info"], "/");
    }


    static public function getRequestMethod(\swoole_http_request $request)
    {
        if (isset($request->server["request_method"])) {
            return $request->server["request_method"];
        }
        return false;

    }

    static public function getRequestPostData(\swoole_http_request $request, $name = "")
    {
        if (strtolower($request->server["request_method"]) == "post") {
            if (!$name) {
                return $request->post;
            }

            if (isset($request->post[$name])) {
                return $request->post[$name];
            }
        }
        return [];
    }

    static public function getRequestGetData(\swoole_http_request $request, $name = "")
    {
            if (!$name) {
                return $request->get;
            }
            if (isset($request->get[$name])) {
                return $request->get[$name];
            }

        return [];
    }


}